package cn.geminis.workflow.service.utils;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

public class ObjectUtils {
    public static <T> T convert(Object source, Class<T> clazz) {
        T vo = BeanUtils.instantiateClass(clazz);
        BeanUtils.copyProperties(source, vo);
        return vo;
    }

    public static <T> List<T> convert(List source, Class<T> clazz) {
        return (List<T>) source.stream().map(r -> {
            return ObjectUtils.convert(r, clazz);
        }).collect(Collectors.toList());
    }
}
